<?php

class Application_Model_User {
	
	protected $_db_table_user;
	
	public function __construct() {
		
		$config = array(
			"name" => "User",
			"primary" => "email"
		);
		$this->_db_table_user = new Zend_Db_Table($config);
		
	}
	
	public function insertUser($email, $password) {
		
		$data = array(
			"email" => $email,
			"password" => $password
		);
		try {
			$this->_db_table_user->insert($data);
		} catch (Exception $e) {
			return false;
		}
		
		return true;
		
	}
	
	public function isUserEmail($email) {
		
		$result = $this->_db_table_user->find($email)->current();
		return $result !== null;
		
	}
	
	public function login($email, $password) {
		
		$where = $this->_db_table_user->select();
		$where->where("email = ?", $email);
		$where->where("password = ?", $password);
		$result = $this->_db_table_user->fetchRow($where);
		return $result !== null;
		
	}
	
}